package com.ss.controller;

import com.ss.domain.Student;
import com.ss.service.StudentService;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
public class StudentController {
    @Autowired
    StudentService studentService;

    @PostMapping("importExcel")
    public void importExcel(MultipartFile file) throws IOException {
//        studentService.importExcel(file);
        studentService.importExcelAsync(file);
    }

    @GetMapping("exportExcel")
    public void exportExcel(HttpServletResponse response) throws IOException {
        studentService.exportExcel(response);
    }

    @GetMapping("exportEncryptExcel")
    public ResponseEntity<ByteArrayResource> exportEncryptExcel(String secretKey) throws Exception {
        return studentService.exportEncryptExcel(secretKey);
    }

    @GetMapping("selectList")
    public List<Student> selectList(){
        return studentService.selectList();
    }
}
